import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法,解决vue路由重复导航错误
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch((err) => err)
}

// 定义静态路由
const constantsRoutes = [
  {
    path: '/',
    redirect: 'index',
    hidden: true
  },
  {
    path: '/index',
    name: 'Index',
    component: () => import('@/view/dashboard/index.vue'),
    meta: { title: '首页', icon: 'el-icon-s-home' }
  },
  {
    path: '/system',
    name: 'System',
    redirect: 'user',
    component: () => import('@/view/system/index.vue'),
    meta: { title: '系统管理', icon: 'el-icon-menu' },
    children: [
      {
        path: '/user',
        name: 'User',
        component: () => import('@/view/system/user/index.vue'),
        meta: { title: '用户管理', icon: 'el-icon-user' }
      },
      {
        path: '/dept',
        name: 'Dept',
        component: () => import('@/view/system/dept/index.vue'),
        meta: { title: '部门管理', icon: 'el-icon-user' }
      },
      {
        path: '/role',
        name: 'Role',
        component: () => import('@/view/system/role/index.vue'),
        meta: { title: '角色管理', icon: 'el-icon-user' }
      },
      {
        path: '/menu',
        name: 'Menu',
        component: () => import('@/view/system/menu/index.vue'),
        meta: { title: '菜单管理', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/configure',
    name: 'Configure',
    redirect: 'user',
    component: () => import('@/view/configure/index.vue'),
    meta: { title: '常规配置', icon: 'el-icon-menu' },
    children: [
      {
        path: '/dict',
        name: 'Dict',
        component: () => import('@/view/configure/dict/index.vue'),
        meta: { title: '字典管理', icon: 'el-icon-user' }
      }
    ]
  },
  {
    path: '/tool',
    name: 'Tool',
    redirect: 'tree',
    component: () => import('@/view/tool/index.vue'),
    meta: { title: '系统工具', icon: 'el-icon-menu' },
    children: [
      {
        path: '/tree',
        name: 'Tree',
        component: () => import('@/view/tool/tree/index.vue'),
        meta: { title: '树形组件', icon: 'el-icon-user' }
      }
    ]
  }
]

// 创建路由实例
const router = new VueRouter({
  routes: constantsRoutes
})

export default router
